package com.hyphenate.easeui.widget.chatrow;

import android.content.Context;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMLocationMessageBody;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMMessage.ChatType;
import com.hyphenate.easeui.R;
import com.hyphenate.exceptions.HyphenateException;
import com.swift.utils.GlideUtil;

public class EaseChatRowHuoDong extends EaseChatRow{

    private ImageView ivHuoDongLogo;  
    private TextView tvDate;  
    private TextView tvTitle;  
    private TextView tvAddress;  
    private TextView tvJoin;  
    private EMLocationMessageBody locBody;

	public EaseChatRowHuoDong(Context context, EMMessage message, int position, BaseAdapter adapter) {
        super(context, message, position, adapter);
    }

    @Override
    protected void onInflatView() {
        inflater.inflate(message.direct() == EMMessage.Direct.RECEIVE ?
                R.layout.ease_row_received_huodong : R.layout.ease_row_send_huodong, this);
    }

    @Override
    protected void onFindViewById() {
    	ivHuoDongLogo = (ImageView) findViewById(R.id.ivHuoDongLogo);
    	tvDate = (TextView) findViewById(R.id.tvDate);
    	tvTitle = (TextView) findViewById(R.id.tvTitle);
    	tvAddress = (TextView) findViewById(R.id.tvAddress);
    	tvJoin = (TextView) findViewById(R.id.tvJoin);
    }


    @Override
    protected void onSetUpView() {
		
    	try {
			tvTitle.setText(message.getStringAttribute("huoDongName"));
			tvDate.setText(message.getStringAttribute("huoDongDate"));
			tvAddress.setText(message.getStringAttribute("huoDongAddress"));
			GlideUtil.load(context, message.getStringAttribute("huoDongCover"), ivHuoDongLogo);
			int status = message.getIntAttribute("huoDongFlag");
			switch (status) {
			case 1:
				tvJoin.setText("等待报名");
				tvJoin.setBackgroundResource(R.drawable.round_huodong_state_small_blue);
				break;
			case 2:
				tvJoin.setText("可参与");
				tvJoin.setBackgroundResource(R.drawable.round_huodong_state_small_blue);
				break;
			case 3:
				tvJoin.setText("待开始");
				tvJoin.setBackgroundResource(R.drawable.round_huodong_state_small_blue);
				break;
			case 4:
				tvJoin.setText("进行中");
				tvJoin.setBackgroundResource(R.drawable.round_huodong_state);
				break;
			case 5:
				tvJoin.setText("活动结束");
				tvJoin.setBackgroundResource(R.drawable.round_huodong_state_gray);
				break;
			case 6:
				tvJoin.setText("活动取消");
				tvJoin.setBackgroundResource(R.drawable.round_huodong_state_gray);
				break;
			default:
				break;
			}
		} catch (HyphenateException e1) {
			e1.printStackTrace();
		}

		// handle sending message
		if (message.direct() == EMMessage.Direct.SEND) {
		    setMessageSendCallback();
            switch (message.status()) {
            case CREATE: 
                progressBar.setVisibility(View.GONE);
                statusView.setVisibility(View.VISIBLE);
                break;
            case SUCCESS:
                progressBar.setVisibility(View.GONE);
                statusView.setVisibility(View.GONE);
                break;
            case FAIL:
                progressBar.setVisibility(View.GONE);
                statusView.setVisibility(View.VISIBLE);
                break;
            case INPROGRESS:
                progressBar.setVisibility(View.VISIBLE);
                statusView.setVisibility(View.GONE);
                break;
            default:
               break;
            }
        }else{
            if(!message.isAcked() && message.getChatType() == ChatType.Chat){
                try {
                    EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
                } catch (HyphenateException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    
    @Override
    protected void onUpdateView() {
        adapter.notifyDataSetChanged();
    }
    
    @Override
    protected void onBubbleClick() {
//    	Toast.makeText(activity, "点击了项目", Toast.LENGTH_SHORT).show();
    }
    
}
